import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      name: 'home',
      component: HomeView,
    },
    {
      path: '/coach',
      name: 'coach',
      component: () => import('../views/Coach.vue'),
    },
    {
      path: '/course',
      name: 'course',
      component: () => import('../views/Course.vue'),
    },
    {
      path: '/sport',
      name: 'sport',
      component: () => import('../views/SportDashboard.vue'),
    },
    {
      path: '/shop',
      name: 'shop',
      component: () => import('../views/Shop.vue'),
    },
    {
      path: '/shop/:id',
      name: 'shop-detail',
      component: () => import('../views/ShopDetail.vue'),
    },
    {
      path: '/user',
      name: 'user',
      component: () => import('../views/User.vue'),
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
    },
    {
      path: '/',
      name: 'Login',
      component: () => import('../views/Login.vue'),
    },
    {
      path: '/realname_auth',
      name: 'realname_auth',
      component: () => import('../views/RealNameAuth.vue'),
    },
    {

      path: '/cs',
      name: 'cs',
      component: () => import('../views/CS.vue'),
    },{
      path: '/search',
      name: 'search',
      component: () => import('../views/Search.vue'),
    },
      {
      path: '/chat',
      name: 'Chat',
      component: () => import('@/views/Chat.vue')
    },
    {
      path: '/chat/:userId?',
      name: 'Chat',
      component: () => import('../views/Chat.vue')
    },
    {
      path: '/map',
      name: 'map-location',
      component: () => import('../views/MapLocation.vue'),
    },
    {
      path: '/cart',
      name: 'Cart',
      component: () => import('../views/Cart.vue')
    },
    {
      path: '/order/:order_no',
      name: 'order-detail',
      component: () => import('../views/OrderDetail.vue')
    },
  ],
})



// router.beforeEach((to, from, next) => {
//   const token = localStorage.getItem('token')
//   if (!token && to.path !== '/') {
//     // 未登录，强制跳转到登录页
//     next({ path: '/' })
//   } else if (token && to.path === '/') {
//     // 已登录访问登录页，跳转到首页
//     next({ path: '/home' })
//   } else {
//     next()
//   }
// })


export default router
